#include <stdio.h>
#include "ohos_init.h"
#include "iot_gpio.h"
#include "iot_gpio_ex.h"

#include "cmsis_os2.h"
#include "tm1637.h"

int led_state = 1;
static TM1637Tube_ts sDisplayData;

void button(void* args ){
    printf("button thread running...\n");
    TM1637_Init(0,1);
    TM1637_Switch(0);//开显示
    TM1637_SetBrightness(0x87);//设置亮度，开显示
    TM1637_WriteCmd(0x44);//写数据到寄存器，固定地址模式
    memset(&sDisplayData, 0x0, sizeof(sDisplayData));
    TM1637_TubeDisplay(sDisplayData);

}

void button_entry(){
    printf("button_entry calbutton \n");

    osThreadAttr_t attr;

    attr.name = "thread_button";
    attr.attr_bits = 0U; // 如果为1 ，则可以使用osThreadJoin函数
    attr.cb_mem = NULL; //控制快的指针
    attr.cb_size = 0U;
    attr.stack_mem = NULL; //栈内存指针
    attr.stack_size = 1024 * 4; //栈大小
    attr.priority = 25; //优先级

    if (osThreadNew((osThreadFunc_t)button, NULL, &attr) == NULL)
    {
        printf("Falied to create thread!\n");
    }


}

APP_FEATURE_INIT(button_entry);

